package com.bwie.controller;

import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user/user")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;

    /**
     * @Auther:手机号登录
     * @Date: 2024/11/4 15:28
     * @Description: TODO
     */
    @PostMapping(value = "/loginMobile")
    public R loginMobile(@Validated @RequestBody LoginInfoVo loginInfoVo, BindingResult bindingResult){
        if (bindingResult.hasFieldErrors()){
            return R.ERROR(400,bindingResult.getFieldError().getDefaultMessage());
        }
            return tbUserService.loginMobile(loginInfoVo);
    }

    /**
     * @Auther:获取用户信息
     * @Date: 2024/11/5 15:33
     * @Description: TODO
     */
    @PostMapping(value = "/getUserById/{userId}")
    public R getUserById(@PathVariable("userId") Integer userId){
        return tbUserService.getUserById(userId);
    }
}
